<template>
  <div :class="className" :style="{ height: height, width: width }" :id="chartOption.bindingDiv">
    <dv-decoration-12 :key="key" :scanDur="dataOption.scanDur" :haloDur="dataOption.haloDur" :color="color" :style="{ height: height, width: width, opacity:opacity}" ref="scanDiv"/>
  </div>
</template>

<script>

import "../../animate/animate.css";

export default {
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
    chartOption: {
      type: Object,
    },
  },
  data() {
    return {
      chart: null,
      opacity: this.chartOption.opacity,
      dataOption: this.chartOption,
      key: 1
    };
  },
  watch: {
    width() {
      this.initChart();
    },
    height() {
      this.initChart();
    },
    chartOption: {
      deep: true,
      handler(newVal) {
        this.setOptions(JSON.parse(JSON.stringify(newVal)));
      },
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  computed:{
    color(){
      let corlorArr = [];
      corlorArr.push(this.dataOption.color1);
      corlorArr.push(this.dataOption.color2);
      return corlorArr
    }
  },
  methods: {
    initChart() {
      this.setOptions(this.chartOption);
    },
    setOptions(dataOption) {
      this.opacity = dataOption.opacity.toString();
      this.key = Math.random();
    },
  },
};
</script>

<style>
</style>